
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mytools;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
import java.util.Map;

/**

 *

 * @author xiaoxiao

 */
public class selfepageAction extends ActionSupport {

    private int pagenumber;
    private int totalpage;
    private int pagesize;

    public selfepageAction() {
    }

    public String execute() throws Exception {
        ActionContext actionContext = ActionContext.getContext();
        Map session = actionContext.getSession();
        String userid = session.get("userid").toString();
        examDAO ed = new examDAO();
        setPagesize(6);
        int selfexamAmount = ed.getselfexamAmount(userid);

        this.setTotalpage(selfexamAmount % getPagesize() == 0 ? (selfexamAmount / getPagesize()) : (selfexamAmount / getPagesize() + 1));
        if (this.getPagenumber() <= 0) {
            this.setPagenumber(1);
        }
        if (this.getPagenumber() > getTotalpage()) {
            this.setPagenumber(getTotalpage());
        }

        return SUCCESS;
    }

    /**
     * @return the pagenumber
     */
    public int getPagenumber() {
        return pagenumber;
    }

    /**
     * @param pagenumber the pagenumber to set
     */
    public void setPagenumber(int pagenumber) {
        this.pagenumber = pagenumber;
    }

    /**
     * @return the totalpage
     */
    public int getTotalpage() {
        return totalpage;
    }

    /**
     * @param totalpage the totalpage to set
     */
    public void setTotalpage(int totalpage) {
        this.totalpage = totalpage;
    }

    /**
     * @return the pagesize
     */
    public int getPagesize() {
        return pagesize;
    }

    /**
     * @param pagesize the pagesize to set
     */
    public void setPagesize(int pagesize) {
        this.pagesize = pagesize;
    }
}
